#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
配置文件
包含数据库连接配置和其他系统配置
"""

import os
from typing import Dict, Any

# 数据库配置
DATABASE_CONFIG = {
    'host': os.getenv('DB_HOST', 'localhost'),
    'port': int(os.getenv('DB_PORT', '3306')),
    'database': os.getenv('DB_NAME', 'fund'),
    'user': os.getenv('DB_USER', 'root'),
    'password': os.getenv('DB_PASSWORD', 'czya31505'),
    'charset': 'utf8mb4',
    'collation': 'utf8mb4_unicode_ci',
    'autocommit': False,
    'raise_on_warnings': True
}

# 爬虫配置
SCRAPER_CONFIG = {
    'request_timeout': 30,
    'retry_times': 3,
    'delay_range': (1, 3),  # 请求间隔时间范围(秒)
    'batch_size': 100,  # 批量处理大小
    'user_agents': [
        'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
        'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
        'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
    ]
}

# 东方财富网站配置
EASTMONEY_CONFIG = {
    'base_url': 'http://fundf10.eastmoney.com',
    'nav_url_template': 'http://fundf10.eastmoney.com/jjjz_{fund_code}.html',
    'api_url_template': 'http://api.fund.eastmoney.com/f10/lsjz',
}

# 日志配置
LOGGING_CONFIG = {
    'level': 'INFO',
    'format': '%(asctime)s - %(name)s - %(levelname)s - %(message)s',
    'file_path': 'logs/fund_nav_scraper.log',
    'max_bytes': 10 * 1024 * 1024,  # 10MB
    'backup_count': 5
}

# 基金代码列表（示例）
SAMPLE_FUND_CODES = [
    '000001',  # 华夏成长混合
    '110022',  # 易方达消费行业股票
    '161725',  # 招商中证白酒指数(LOF)A
    '519674',  # 银河创新成长混合
    '000248',  # 汇添富中证主要消费ETF联接A
]

def get_database_config() -> Dict[str, Any]:
    """获取数据库配置"""
    return DATABASE_CONFIG.copy()

def get_scraper_config() -> Dict[str, Any]:
    """获取爬虫配置"""
    return SCRAPER_CONFIG.copy()

def get_eastmoney_config() -> Dict[str, Any]:
    """获取东方财富配置"""
    return EASTMONEY_CONFIG.copy()

def get_logging_config() -> Dict[str, Any]:
    """获取日志配置"""
    return LOGGING_CONFIG.copy()